<?php namespace App\Core\Metadata;

use App\Core\Exceptions\RuntimeError;

abstract class Meta {
    
    use Fielder, Filler, Namer, Ruler;
    
    public $fields = [];
    
    public function getFields($fields = '*'){
        if($fields == '*'){
            return $this->fields;
        }
        $fieldKyes = is_array($fields) ? $fields : func_get_args();
        $fieldItems = [];
        foreach($fieldKyes as $field){
            $fieldItems[$field] = $this->getField($field);
        }
        return $fieldItems;
    }
    
    public function getField($fieldName){
        if(!isset($this->fields[$fieldName])){
            throw new RuntimeError('Matadata format error.Field "'.$fieldName.'" not found');
        }
        return $this->fields[$fieldName];
    }
}